package com.bytecollege.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bytecollege.model.CourseCollect;
import com.bytecollege.vo.CourseCollectVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;


import java.util.List;

/**
 * @ClassName: CollectMapper
 * @Description:
 * @Author: Sun
 * @Date: 2022/10/18 21:03
 */
@Mapper
public interface CourseCollectMapper extends BaseMapper<CourseCollect> {
   /**
    * 查询某课程的收藏量
    * @param courseId
    * @return
    */
   @Select("select count(coursecollect_id) from coursecollect where course_id = #{courseId}")
   Integer getCollectNumByCourseId(Integer courseId);


   /**
    * 收藏
    * @param page
    * @param userId
    * @return
    */
   @Select("select  r.CourseCollect_Id ,c.Course_Id,u.User_Id,r.AddTime, c.Course_Url,c.Course_Name,c.Course_Clicks,c.Course_Pic  from coursecollect r left join course c on r.Course_id = c.Course_Id left join user u on r.User_id = u.User_Id where u.User_Id = #{userId}")
   List<CourseCollectVo> getCourseCollect(Page page, Integer userId);

   /**
    * 查询单个收藏
    * @param courseId
    * @param userId
    * @return
    */
   @Select("select coursecollect_id,course_id,user_id,addtime from coursecollect where course_id=#{courseId} and user_id=#{userId}")
   CourseCollect getOne(Integer courseId,Integer userId);

   /**
    * 添加收藏
    * @param courseCollect
    * @return
    */
   @Select("insert into coursecollect(course_id,user_id,addtime) values (#{courseId},#{userId},#{addTime})")
   Integer add(CourseCollect courseCollect);


   @Delete("delete from coursecollect where CourseCollect_id = #{id} ")
   Integer del(Integer id);

}